﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


class HallOfFame
{
    private List<Player> hallOfFame;

    private static HallOfFame HOF;

    private HallOfFame()
    {
        this.hallOfFame = new List<Player>();
    }

    public static HallOfFame GenerateHOF()
    {
        if(HOF==null)
        {
            HOF= new HallOfFame();
        }
        return HOF;
    }

    public void AddPlayer(Player p)
    {
        if (this.hallOfFame.Count == 10)
        {
            if (p.Result > this.hallOfFame[hallOfFame.Count - 1].Result)
            {
                this.hallOfFame.Add(p);
                this.hallOfFame.Sort();
                if (this.hallOfFame.Count > 10)
                {
                    this.hallOfFame.RemoveAt(10);//keep only 10 players in the hall of fame

                }
            }
        }
        else
        {
            this.hallOfFame.Add(p);
            this.hallOfFame.Sort();
        }
    }

    public void Display()
    {
        Console.Clear();
        int row = 22;
        ConsoleTweaks.CenterTextOnRow("******************************", 15);
        ConsoleTweaks.CenterTextOnRow("*                            *", 16);
        ConsoleTweaks.CenterTextOnRow("*        HALL OF FAME        *", 17);
        ConsoleTweaks.CenterTextOnRow("*                            *", 18);
        ConsoleTweaks.CenterTextOnRow("******************************", 19);
        foreach (Player p in this.hallOfFame)
        {
            int pL = p.Name.Length;
            int sL = p.Result.ToString().Length;
            int pointsCount = 79 - (pL + sL);
            string entry = p.Name + new String('.',pointsCount)+ p.Result;
            ConsoleTweaks.CenterTextOnRow(entry, row);
            row++;
        }
    }
}

